﻿using Microsoft.AspNetCore.Mvc;
using MVC系统mvc.Dto.Purch;
using MVC系统mvc.Dto.Quality;
using MVC系统mvc.Dto.RawMater;
using MVC系统mvc.Views.Quality;
using Newtonsoft.Json;
using System.Reflection;
using WMS_MAV;

namespace MVC系统mvc.Controllers
{
    public class QualityController : Controller
    {

        private readonly IConfiguration _configuration;

        public QualityController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 质检控制器
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 质检组显示
        /// </summary>
        /// <returns></returns>
        public IActionResult QgroupIndexShow()
        {
            return View();
        }
        /// <summary>
        /// 新增复检信息
        /// </summary>
        /// <returns></returns>
        public IActionResult ReInfIndexCreate()
        {
            return View();
        }
        /// <summary>
        /// 复检信息显示
        /// </summary>
        /// <returns></returns>
        public IActionResult ReInfIndexShow()
        {
            return View();
        }
        /// <summary>
        /// 复检（已合格）信息显示
        /// </summary>
        /// <returns></returns>
        public IActionResult HegeReInShow()
        {
            return View();
        }
        /// <summary>
        /// 复检(不合格)信息显示
        /// </summary>
        /// <returns></returns>
        public IActionResult BuHegeReInfIndexShow()
        {
            return View();
        }
        /// <summary>
        /// 待复检去复检
        /// </summary>
        /// <returns></returns>
        public IActionResult ReInfICreate()
        {
            return View();
        }
        /// <summary>
        /// 质检方案显示
        /// </summary>
        /// <returns></returns>
        public IActionResult QgroupPinShow()
        {
            return View();
        }
        /// <summary>
        /// 原料质检表修改
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateRaw()
        {
            return View();
        }
        /// <summary>
        /// 原料质检表详情
        /// </summary>
        /// <returns></returns>
        public IActionResult GetIdRaw()
        {
            return View();
        }
        /// <summary>
        /// 原料质检列表
        /// </summary>
        /// <returns></returns>
        public IActionResult MaterialTable()
        {
            var apiUrl = _configuration["Url"];
            return View(new { ApiUrl = apiUrl });
        }
        /// <summary>
        /// 添加复检
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddReIn(AddReInDto model, string token)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/ReInspection/AddReInspection";
            string url = _configuration["Url"] + "zread/api/ReInspection/AddReInspection";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 复检显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ShowReIn(ReInDto model)
        {
           
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            //string url = "http://localhost:65178/api/ReInspection/GetQualityPlanList?ReinspectionCode="+model.ReinspectionCode+
                //"&ReinspectionName="+model.ReinspectionName+"&ReinspectionSarte="+model.ReinspectionSarte+"&Pageindex="+model.Pageindex+"&Pagesize="+model.Pagesize;
            string url = _configuration["Url"] + "zread/api/ReInspection/GetQualityPlanList?ReinspectionCode=" + model.ReinspectionCode+
            "&ReinspectionName="+model.ReinspectionName+"&ReinspectionSarte="+model.ReinspectionSarte+"&Pageindex="+model.Pageindex+"&Pagesize="+model.Pagesize;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        ///复检单删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDeleteReInfo(int ReinspectionId, string token)
        {
           
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/ReInspection/DelReInforce?ReinspectionId=" + ReinspectionId;
            string url = _configuration["Url"] + "zread/api/ReInspection/DelReInforce?ReinspectionId=" + ReinspectionId;
            var response = await httpClientWrapper.PostAsync(url, ReinspectionId.ToString());
            return Json(response);
        }
        /// <summary>
        /// 复检反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetByidRein(int ReinspectionId,string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/ReInspection/GetByidReInsp?ReinspectionId="+ ReinspectionId;
            string url = _configuration["Url"] + "zread/api/ReInspection/GetByidReInsp?ReinspectionId=" + ReinspectionId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 销毁
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> XiaohuiRein(Xioahui obj1, string token)
        {
           
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            ////string url = "http://localhost:65178/api/ReInspection/XiaohuiReIns?ReinspectionId="+obj1.ReinspectionId+"&RawMaterialQualityId="+obj1.RawMaterialQualityId;
            string url = _configuration["Url"] + "zread/api/ReInspection/XiaohuiReIns?ReinspectionId=" + obj1.ReinspectionId + "&RawMaterialQualityId=" + obj1.RawMaterialQualityId;
            string list = JsonConvert.SerializeObject(obj1);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 复检修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdateRew(UpdateRewDto field, string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/ReInspection/UpdateReInspection";
            string url = _configuration["Url"] + "zread/api/ReInspection/UpdateReInspection";
            string list = JsonConvert.SerializeObject(field);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 原料质检显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ShowMaterialss(RawSpectionShowDTO model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/GetList?RNumber="+model.RNumber+"&MNumber="+model.MNumber+"&State="+model.State;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 原料质检添加
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMaterial()
        {
            var apiUrl = _configuration["Url"];
            return View(new { ApiUrl = apiUrl });
        }
        /// <summary>
        /// 质检项目反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> QualitySpectionFanDo(Bacckfillsoection model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/ShowSpection?QualityPlanName="+model.QualityPlanName;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加原料质检
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddTianRawMATER(RawMaterAddDto model)
        {
            HttpClientWrapper client = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/AddRMQ";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 原料质检显示(详情)
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> RawList(string token)
        {

            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/RawMaterialQuality/GetList";
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/GetList";
            //var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        ///原料质检表单删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDeleteRaw(int RawMaterialQualityId,string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/RawMaterialQuality/RemoveRMQ?RawMaterialQualityId=" + RawMaterialQualityId;
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/RemoveRMQ?RawMaterialQualityId=" + RawMaterialQualityId;
            var response = await httpClientWrapper.PostAsync(url, RawMaterialQualityId.ToString());
            return Json(response);
        }
        /// <summary>
        /// 原料质检表反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> RawGetid(int RawMaterialQualityId, string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/RawMaterialQuality/ShowRMQ?RawMaterialQualityId=" + RawMaterialQualityId;
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/ShowRMQ?RawMaterialQualityId=" + RawMaterialQualityId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 原料质检修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdateRawRaw(UpdateRawss obj1, string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:65178/api/RawMaterialQuality/UpdRMQ";
            string url = _configuration["Url"] + "zread/api/RawMaterialQuality/UpdRMQ";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 原料质检编辑
        /// </summary>
        /// <returns></returns>
        public IActionResult EditMaterial()
        {
            var apiUrl = _configuration["Url"];
            return View(new { ApiUrl = apiUrl });
        }

        /// <summary>
        /// 原料质检查看
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowMaterial()
        {
            var apiUrl = _configuration["Url"];
            return View(new { ApiUrl = apiUrl });
        }

        /// <summary>
        /// 质检方案显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> DeviceDoPlan(QualityPlanShow model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/QualityPian/GetQualityPlanList?QualityPlanCode=" +model.QualityPlanCode+"&QualityPlanSart="+model.QualityPlanSart+"&Pageindex="+model.Pageindex+"&Pagesize="+model.Pagesize;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改质检方案状态
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsUpdateSarte(QualityPlanUpdateSarte model)
        {
       
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/QualityPian/UpdateQualityPlanSarte?QualityPlanId=" + model.QualityPlanId + "&QualityPlanSart="+ model.QualityPlanSart;
            string list = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 质检组显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> DeviceDo(QualityGroupShow model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"]+ "zread/api/Qualitygroup/Show?Pageindex=" +model.Pageindex+"&Pagesize="+model.Pagesize+"&QualitygroupBH="+model.QualitygroupBH+"&QualitygroupName="+model.QualitygroupName;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加质检组
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetAllocationAdd(QualityGroupAddDto model)
        {
            HttpClientWrapper client = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/Qualitygroup/AddQualitygroup";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }


     /// <summary>
     /// 质检组单删
     /// </summary>
     /// <param name="model"></param>
     /// <param name="token"></param>
     /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDelDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "zread/api/Qualitygroup/DelQualitygroup";
            var response = await httpClientWrapper.PostAsync(url,model);
            return Json(response);
        }

        /// <summary>
        /// 质检组反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> QualityGroudFanDo(QualityGroupBackfillDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/Qualitygroup/BackfillQualitygroup?QualitygroupId=" + model.QualitygroupId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 质检组修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> QualityGroupupdateDo(QualityGroupUpdateDto obj1, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "zread/api/Qualitygroup/UpdateQualitygroup";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }


        /// <summary>
        /// 质检项目视图
        /// </summary>
        /// <returns></returns>
        public IActionResult QualityinspectionShow()
        {
            return View();
        }
        /// <summary>
        /// 质检项目显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> QualspectionShow(QualityinspectionShowDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/Qualityspection/Showspection?Pageindex=" +model.Pageindex+"&Pagesize="+model.Pagesize+"&QualityinspectionBH="+model.QualityinspectionBH+"&CreatedDate="+model.CreatedDate;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加质检项目
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> QualspectionAdd(QualityinspectionAddDto model)
        {
            HttpClientWrapper client = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/Qualityspection/AddQualityspection";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 质检项目删除
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDelDoQpeion(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "zread/api/Qualityspection/DelQualitspection";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }

        /// <summary>
        /// 质检项目反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> QpeionFanDo(QualityspectionBackfillDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/Qualityspection/BackfillQualityspection?QualityinspectionId=" + model.QualityinspectionId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }


        /// <summary>
        /// 质检项目修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> QualityspectionupdateDo(QualityspectionUpdateDto obj1, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "zread/api/Qualityspection/UpdateQualityspection";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 质检方案添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult QualityPlanAdd()
        {
            return View();
        }

        /// <summary>
        /// 添加质检方案
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> QualityPlanAddTian(QualityPlanAddDto model)
        {
            HttpClientWrapper client = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "zread/api/QualityProgrom/AddQualitProgrom";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 质检方案修改视图
        /// </summary>
        /// <returns></returns>
        public IActionResult QualityPianUpdate()
        {
            return View();
        }

        /// <summary>
        /// 质检项目反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> QpianBackfill(string QualityPlanCode, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "zread/api/QualityProgrom/BackfillQualityspection?QualityPlanCode="+ QualityPlanCode;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        /// 质检项目修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> QualityspectionUodate(QualityPlanAddDto obj)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(obj.token);
            string url = _configuration["Url"] + "zread/api/QualityProgrom/UpdateQualityspection";
            string list = JsonConvert.SerializeObject(obj);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }
    }
}
